﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LetterOfAdvice.aspx.cs" Inherits="Skyworth.CRM.Web.Orders.LetterOfAdvice" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>发货通知单</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <%--[if IE]>
     <link href="../themes/css/ieHack.css" rel="stylesheet" type="text/css" />
    <![endif]--%>
    <link href="../themes/<%= Request.Cookies["dwz_theme"]!=null? Request.Cookies["dwz_theme"].Value:"default" %>/style.css"
        rel="stylesheet" type="text/css" />
    <link href="../themes/css/core.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/pages.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/wbox.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/Messagebox.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" media="screen" href="../themes/JQuery-UI-1.8.16/jquery-ui-1.8.16.custom.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="../themes/ui.jqgrid.css" />
     
    <script src="../javascripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../javascripts/jquery-ui-1.8.16.js"></script>
    <script src="../javascripts/jquery.layout-1.3.js" type="text/javascript"></script>
    <script src="../javascripts/json2.js" type="text/javascript"></script>
    <script src="../javascripts/dwz.core.js" type="text/javascript"></script>
    <%--<script src="../javascripts/dwz.pagination.js" type="text/javascript"></script>--%>           <script type="text/javascript" charset="utf-8" src="../javascripts/JGrid4.2.0/i18n/grid.locale-cn.js"></script>
    <script type="text/javascript" charset="utf-8" src="../javascripts/JGrid4.2.0/grid.base.js"></script>
    <script type="text/javascript" charset="utf-8" src="../javascripts/JGrid4.2.0/grid.common.js"></script>
    <script type="text/javascript" charset="utf-8" src="../javascripts/JGrid4.2.0/grid.formedit.js"></script>
    <script type="text/javascript" charset="utf-8" src="../javascripts/JGrid4.2.0/grid.custom.js"></script>
    <script type="text/javascript" charset="utf-8" src="../javascripts/JGrid4.2.0/grid.postext.js"></script>
    <script type="text/javascript" charset="utf-8" src="../javascripts/JGrid4.2.0/jquery.fmatter.js"></script>
    <script type="text/javascript" charset="utf-8" src="../javascripts/JGrid4.2.0/JsonXml.js"></script>    <link type="text/css" rel="stylesheet" href="../themes/layout-default-latest.css" />
 
    <script src="../javascripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>

    <script type="text/javascript">
        function setHeight() {
            jQuery("#list").jqGrid('setGridHeight', $(".ui-layout-content").height() - $(".ui-layout-content .ui-jqgrid-titlebar").height() - $(".ui-layout-content .ui-jqgrid-hdiv").height() - $(".ui-layout-content #pager").height() - 11).jqGrid('setGridWidth', "100%");
            jQuery("#detail").jqGrid('setGridHeight', $(".ui-layout-south").height() - $(".ui-layout-south .ui-jqgrid-titlebar").height() - $(".ui-layout-south .ui-jqgrid-hdiv").height() - $(".ui-layout-south #detailPager").height() - 11).jqGrid('setGridWidth', "100%");
        }
        $(document).ready(function() {
            var layout = $('body').layout({
                center__minHeight: 385,
                south__size: 280,
                center__onresize: function() {
                    setHeight();
                }
            });
            //layout.allowOverflow("center");

            $("div.panelBar li").hover(function() { $(this).addClass("hover"); },
                                     function() { $(this).removeClass("hover"); })
            $("input[type=text]").addClass("textInput").focusClass("focus");
            //$("table.table").jTable();
            $("#list").jqGrid({
                datatype: getLetterOfAdvice,
                mtype: 'POST',
                colNames: ['Fitemid', '单号', '日期', '客户', '购货单位', '币别', '部门', '业务员', '制单人'],
                colModel: [
                  { name: 'Fitemid', index: 'Fitemid', hidden: true },
                  { name: 'Fnumber', index: 'Fnumber', width: 90 },
                  { name: 'Fdate', index: 'Fdate', width: 90, formatter: JosnDateFormatter },
                  { name: 'FCustid', index: 'FCustid' },
                  { name: 'FBuyDept', index: 'FBuyDept' },
                  { name: 'FCyID', index: 'FCyID' },
                  { name: 'FDept', index: 'FDept' },
                  { name: 'Fsalse', index: 'Fsalse' },
                  { name: 'FEmpName', index: 'FEmpName' }
                ],
                pager: '#pager',
                pagerpos: "left",
                multiselect: false,
                rowNum: 20,
                rowList: [20, 10, 30, 40, 50],
                sortname: 'Fnumber',
                sortorder: 'desc',
                viewrecords: true,
                gridview: true,
                height: 220,
                autowidth: true,
                rownumbers: true,
                caption: '发货通知单',
                jsonReader: {
                    repeatitems: false,
                    id: "Fitemid",
                    root: "rows",
                    page: "page",
                    total: "total",
                    records: "records"
                },
                onSelectRow: function(ids) {
                    var detailTable = $("#detail");
                    var row = $("#list").getRowData(ids);
                    detailTable.jqGrid('setCaption', "发货通知明细【单号：" + row['Fnumber'] + "】");
                    detailTable.jqGrid('setGridParam', { url: "LetterOfAdvice.aspx/GetDetailedLetterOfAdvice?id=" + ids, page: 1 });
                    detailTable.appendPostData({ id: ids });
                    detailTable.trigger('reloadGrid');
                }
            });
            $("#btnAdd").click(function() {
                $("#list").trigger("reloadGrid");
                return false;
            })
            $("#btnExport").click(function() {
                var postdata = $("#list").getPostData();
                var url = "../service/LetterOfAdvice.ashx?code=" + postdata.code + "&startDate=" + postdata.startDate + "&endDate=" + postdata.endDate + "&customer=" + postdata.customer + "&department=" + postdata.department + "&sales=" + postdata.sales + "&sidx=" + postdata.sidx + "&sord=" + postdata.sord
                $("#export2Excel").attr("src", url);
                return false;
            })

            $("#detail").jqGrid({
                datatype: getDetailedLetterOfAdvice,
                mtype: 'POST',
                colNames: ['Fitemid', 'FSaleStockID', 'Fproductid', '销售订单编号', '订单编码', '通知单日期', '产品编码', '产品名称', '单位', '数量', '单价', '金额', '是否红字发货'],
                colModel: [
                  { name: 'Fitemid', index: 'Fitemid', hidden: true },
                  { name: 'FSaleStockID', index: 'FSaleStockID', hidden: true },
                  { name: 'Fproductid', index: 'Fproductid', hidden: true },
                  { name: 'FOrderID', index: 'FOrderID' },
                  { name: 'FOrdernumber', index: 'FOrdernumber' },
                  { name: 'FDate', index: 'FDate', width: 120, formatter: JosnDateFormatter },
                  { name: 'FProductnumber', index: 'FProductnumber' },
                  { name: 'FProductname', index: 'FProductname' },
                  { name: 'Funit', index: 'Funit', align: "center" },
                  { name: 'FQTy', index: 'FQTy', align: "right", formatter: 'number' },
                  { name: 'FPrice', index: 'FPrice', align: "right", formatter: 'currency' },
                  { name: 'FAmount', index: 'FAmount', align: "right", formatter: 'currency' },
                  { name: 'FisR', index: 'FisR', align: "center", formatter: 'checkbox' }
                ],
                pager: '#detailPager',
                pagerpos: "left",
                rowNum: 20,
                rowList: [20, 10, 30, 40, 50],
                sortname: 'FOrdernumber',
                sortorder: 'desc',
                viewrecords: true,
                gridview: true,
                height: 250,
                autowidth: true,
                rownumbers: true,
                caption: '发货通知明细',
                jsonReader: {
                    repeatitems: false,
                    id: "Fitemid",
                    root: "rows",
                    page: "page",
                    total: "total",
                    records: "records"
                }
            });

            setHeight();

        });
        function JosnDateFormatter(cellvalue, options, rowObject) {
            var newDate = eval("new " + cellvalue.replace(/\//g, ""));
            var month = newDate.getMonth() + 1;
            month = month < 10 ? "0" + month : month;
            var date = newDate.getDate();
            date = date < 10 ? "0" + date : date;
            return newDate.getFullYear() + "-" + month + "-" + date;
        }

        function getLetterOfAdvice(postdata) {

            postdata.code = $("#txtCode").val();
            postdata.startDate = $("#txtStartDate").val();
            postdata.endDate = $("#txtEndDate").val();
            postdata.customer = $("#txtCust").val();
            postdata.department = $("#txtDepartment").val();
            postdata.sales = $("#txtSales").val();

            jQuery.ajax({
                type: "POST",
                url: 'LetterOfAdvice.aspx/GetLetterOfAdvice',
                data: JSON.stringify(postdata),
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function(data) {
                    var thegrid = $("#list")[0];
                    thegrid.addJSONData(jQuery.parseJSON(data.d));
                }
            });
        }
        function getDetailedLetterOfAdvice(postdata) {
            if (postdata.id) {
                jQuery.ajax({
                    type: "POST",
                    url: "LetterOfAdvice.aspx/GetDetailedLetterOfAdvice",
                    data: JSON.stringify(postdata),
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    success: function(data) {
                        var thegrid = $("#detail")[0];
                        thegrid.addJSONData(jQuery.parseJSON(data.d));
                    }
                });
            }
        }
      
    </script>

</head>
<body>
    <div class="ui-layout-center">
        <div class="pane-header">
             <form id="form1" runat="server">
                <table width="100%" id="QueryArea">
                    <tr>
                        <td>
                            <div class="searchBar searchPanel">
                                <table>
                                    <tr>
                                        <td class="floatLeft">
                                            <span>单号：</span>
                                                <asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
                                            </td>
                                            <td class="floatLeft paddingLeft10"><span>日期：</span>
                                                <asp:TextBox ID="txtStartDate" runat="server" onClick="WdatePicker({skin:'ext',maxDate:'#F{$dp.$D(\'txtEndDate\')}'})"
                                                    ReadOnly="True"></asp:TextBox>
                                            </td>
                                            <td class="floatLeft paddingLeft10"><span>至</span><span style="padding-left: 35px">
                                                <asp:TextBox ID="txtEndDate" runat="server" onClick="WdatePicker({skin:'ext',minDate:'#F{$dp.$D(\'txtStartDate\')}'})"
                                                    ReadOnly="True"></asp:TextBox>
                                            </span></td>
                                            <td class="clearBoth"></td>
                                        
                                    </tr>
                                    <tr style="height: 8px;"></tr>
                                    <tr >
                                        <td class="floatLeft"><span>客户：</span>
                                                <asp:TextBox ID="txtCust" runat="server"></asp:TextBox>
                                            </td>
                                            <td class="floatLeft paddingLeft10"><span>部门：</span>
                                                <asp:TextBox ID="txtDepartment" runat="server"></asp:TextBox>
                                            </td>
                                            <td class="floatLeft paddingLeft10"><span>业务员：</span>
                                                <asp:TextBox ID="txtSales" runat="server"></asp:TextBox>
                                            </td>
                                            <td class="clearBoth"></td>                                        
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div class="panelBar">
                                <ul class="toolBar">
                                    <li class="">
                                        <asp:LinkButton ID="btnAdd" CommandArgument="2" runat="server" CssClass="add"><span>查 询</span> </asp:LinkButton></li>
                                    <li class="line">line</li>
                                    <li class="">
                                        <asp:LinkButton ID="btnExport" CommandArgument="3" runat="server" CssClass="edit"><span>导出到Excel</span> </asp:LinkButton></li>
                                    <li class="line">line</li>                         
                                    
                                </ul>
                            </div>
                        </td>
                    </tr>           
                </table>
            </form>
        </div>
         <div class="ui-layout-content">
            <table id="list" ></table> 
            <div id="pager"></div>            
         </div>        
    </div>
    <div class="ui-layout-south">
           <table id="detail"></table>
           <div id="detailPager"></div>  
    </div>
    <iframe id="export2Excel" src="" style="display:none"></iframe>
    
</body>
</html>
